package main

import (
	"fmt"
	"sync"
	"time"
)

var lock sync.Mutex
var set = make(map[int]bool)

func printOnce(num int) {
	lock.Lock()
	defer lock.Unlock()

	if _, exist := set[num]; !exist {
		fmt.Println(num)
	}
	set[num] = true // 错误访问
}

//func main() {
//	for i := 0; i < 10; i++ {
//		go printOnce(100)
//	}
//	time.Sleep(time.Second)
//}

func main() {
	for i := 0; i < 20; i++ {
		go printOnce(666)
	}
	time.Sleep(time.Second)
}
